#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
 
int main (void) 
{
    int a=100,b=200,c;
    int n, fd;
    char read_buf[256] ={};
    char *p =NULL;
    char write_buf[256];
 
    memcpy(write_buf,&a,sizeof(a));
    memcpy(write_buf+sizeof(a),&b,sizeof(b));
    fd = open ("/dev/hello", O_RDWR);
    if (fd < 0) {
        perror("open");
        exit(0);
    }
    printf ("/dev/hello opened, fd=%d!\n", fd);
 
     /* write */
    printf("Write a=%d b=%d\n", a,b);
    if (write (fd, write_buf, 8) < 0)
    {
        perror("fail to write");
    }
 
    /* read */
    printf ("Read returns add(a,b)=%d\n", (int)read (fd, read_buf,12));

    close (fd);
    printf ("/dev/hello closed!\n");
    return 0;
 
}
